$(document).ready(function(){

  $(".cancelMail").live('click', function() {
      $("#send_email_message").hide();
      $("#send_email_form").html('');
  });

  $(".cancelReply").live('click', function() {
      $(".reply-box").html('');
  });

  $('.forward-button').click(function(){
      message_id = jQuery(this).attr('id');
        
      $( "#dialog" ).dialog({
          width: 360,
          title: "Please enter Email.", 
          buttons: { 
              "Send": function() { 
                      email = $("#forward_mail").val();
                      if(email != ''){
                        jQuery.ajax({
                                type: "POST",
                                url: cfg+"admin/tickets/forward_message/"+message_id+'/'+email,
                                success: function(msg){
                                   alert(msg);
                                   jQuery("#dialog").dialog("close");
                                }
                         })
                      }else{
                          alert('Please enter email.');
                          return false;
                      } 
                    },
              "Cancel": function(){
                      jQuery(this).dialog("close"); 
              } 
          } 
      });
  });    

  
  $(function() {
    $( "#accordion" ).accordion({collapsible:true, active: false});
  });
  
  $('#change_status').live('change', function(){
      $('#reason').show();
  });
  $("#MessageLanguage").bind('change',function(e){
      templateID = $('#MessageTemplateId').val();
        if(templateID){
          $.ajax({
            dataType: "html", 
            success:function (data, textStatus) { 
                $("#template-preview").show().html(data);
            }, 
            url: cfg+"admin/messages/load_template/"+templateID+"/"+$(this).val()
          });
        }
      return false;
  });
  /*$("#MessageTemplateId").bind("change", function (event){  
      templateID = $(this).val();
      if(templateID){
        $.ajax({
          dataType: "html", 
          success:function (data, textStatus) { 
              $("#template-preview").show().html(data);
          }, 
          url: cfg+"admin/messages/load_template/"+templateID
        });
      }
    return false;
  });*/
  /*
  $("#mcNewMessage").bind("click", function (){ 
      id = $("#ticketId").val();
      $.ajax({
        url: cfg+"admin/tickets/reply/"+id,
        success:function (data) {  
              $("#send_email_message").show();
              $("#send_email_form").html(data);


        } 
      });
  });
  */


/***************** Help Desk ************************/


/***************** Help Desk ************************/
  
});

  function validateFor(){
        reason = $('#TicketReasonReason').val();
        if(reason == ''){
            alert('Please enter reason to change the Ticket Status.');
            return false;
        }
        return true;
  }
  